package com.ala4.oxcafe.boot.web;

import com.ala4.oxcafe.boot.interceptor.WebLoggerInterceptor;
import com.ala4.oxcafe.properties.FileProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author PING
 * @version 1.0.0
 * @date 2025/7/31 16:15
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    private final FileProperties fileProperties;

    public WebMvcConfig(FileProperties fileProperties) {
        this.fileProperties = fileProperties;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 静态资源
        registry.addResourceHandler(fileProperties.getStaticAccessPath()).addResourceLocations("file:" + fileProperties.getUploadFolder());
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 日志拦截器
        registry.addInterceptor(new WebLoggerInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/favicon.ico");
    }

}
